import java.util.*;

class GlobalEnv implements Env {
    Map<String, Type> global =  new HashMap<String, Type>();
    
    
    public GlobalEnv()
    {
	
    }
    
      public void insert(String s, Type t, Position p) {
	  //System.out.println("Globally inserting "+s);
	/*if (global.get(s) != null)
	    SemanticCheck.
	    semanticError("Identifier "+s+" doubly defined", p); */
	global.put(s,t);
	}

    public void insert(String s, Type t) throws SemanticException
    {
	//System.out.println("Globally inserting "+s);
	if (global.get(s) != null)
	    //SemanticCheck.semanticError("Identifier "+s+" doubly defined");
	    //System.out.println("symbol already defined");
	    throw new SemanticException("Identifier " + s +" doubly defined");
	global.put(s,t);
    }
    

    public Type lookup(String s) {
	//System.out.println("Global lookup: "+s);
	return global.get(s);
    }

    public void setResult(Type t) {
	throw new IllegalStateException("No result type in global environment");
    }

    public Type getResult() {
	throw new IllegalStateException("No result type in global environment");
    }

    public LocalEnv enter() {
	return new LocalEnv(this);
    }

    public void print()
    {
	int nrEntries = global.size();
	Set entries = global.entrySet();

	Iterator i = entries.iterator();
	
 	System.out.println("*****BEGIN GLOBAL TABLE **********");
	while(i.hasNext())
	{
	    Map.Entry entry = (Map.Entry)i.next(); 
	    System.out.println("[" + entry.getKey() + "][" + entry.getValue().toString() + "]");
	}		
 	System.out.println("*****END GLOBAL TABLE **********");
    }
}
